using System.IO;

namespace WorldRacing2.Scenario.WR2TerrainLoader.QadFile
{
    public class Sound
    {
        #region Private Fields

        /// <summary>
        /// delay : 10 = sec)
        /// </summary>
        private short delay;

        private float PositionX;
        private float PositionY;
        private float PositionZ;
        private short radius;
        private ObjectName soundName;
        private EnumSoundType soundType;
        private short tempo;
        private short unknown;
        private byte[] unknown2 = new byte[12];
        private short volume;

        #endregion Private Fields

        #region Public Methods

        public static Sound FromStream(BinaryReader br)
        {
            Sound sound = new Sound();
            sound.PositionX = br.ReadSingle();
            sound.PositionY = br.ReadSingle();
            sound.PositionZ = br.ReadSingle();
            sound.soundName = ObjectName.FromStream(br);
            sound.volume = br.ReadInt16();
            sound.tempo = br.ReadInt16();
            sound.radius = br.ReadInt16();
            sound.soundType = (EnumSoundType)br.ReadUInt16();
            sound.unknown = br.ReadInt16();
            sound.delay = br.ReadInt16(); // (value : 10 = sec)
            sound.unknown2 = br.ReadBytes(12);

            return sound;
        }

        #endregion Public Methods

        #region Internal Methods

        /// <summary>
        /// Saves the specified bw.
        /// </summary>
        /// <param name="bw">The bw.</param>
        internal void Save(BinaryWriter bw)
        {
            bw.Write(this.PositionX);
            bw.Write(this.PositionY);
            bw.Write(this.PositionZ);
            this.soundName.Save(bw);
            bw.Write(this.volume);
            bw.Write(this.tempo);
            bw.Write(this.radius);
            bw.Write((short)this.soundType);
            bw.Write(this.unknown);
            bw.Write(this.delay);
            bw.Write(unknown2);
        }

        #endregion Internal Methods
    }
}